package servlet;

import com.alibaba.fastjson.JSON;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;

public class AjaxFindServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    doGet(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html;charset=UTF-8");
        response.setHeader("Access-Control-Allow-Origin","*");
        String value=request.getParameter("value");
        ArrayList arrayList=new ArrayList();
        if("0".equals(value)){
            arrayList.add("福州");
            arrayList.add("三明");
            arrayList.add("龙岩");
        }else if("1".equals(value)){
            arrayList.add("广州");
            arrayList.add("深圳");
            arrayList.add("东莞");
        }else if("2".equals(value)){
            arrayList.add("成都");
            arrayList.add("绵阳");
            arrayList.add("自贡");
        }
        String text = JSON.toJSONString(arrayList);
        response.getWriter().write(text);
    }
}
